//
//  NewFuLiViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2018/3/16.
//  Copyright © 2018年 李 佳伟. All rights reserved.
//

#import "NewFuLiViewController.h"
#import "JTCSM.h"
#import "NewFuLiTableViewCell.h"
@interface NewFuLiViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView *_tableview;
}

@end

@implementation NewFuLiViewController
- (void)gotBack{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [df isRemoveTarbar:YES];
    self.navigationController.navigationBar.hidden = NO;
    self.view.backgroundColor =[UIColor whiteColor];
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.leftBarButtonItem = [leftbtn setBarButtonItemsImageName:@"fanhui.png" frame:KLeftBarButtonItemFrame_image target:self SEL:@selector(gotBack)];
    // Do any additional setup after loading the view.
    [self layoutTableView];
}

- (void)layoutTableView{
    
    _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, KCONTROLLERHeight) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    [self.view addSubview:_tableview];
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self setUpTableView];
    //    view.backgroundColor = RGBACOLOR(241, 241, 241, 1);
}

- (void)setUpTableView{
    // 1.下拉刷新(进入刷新状态就会调用self的headerRereshing)
    [_tableview addHeaderWithTarget:self action:@selector(headerRereshing)];
    
    // 上拉加载
    [_tableview addFooterWithTarget:self action:@selector(footerRereshing)];
    
}
- (void)headerRereshing{
    // 2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KRefreshTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //getMarriageSeeking(网络请求)
        //        [self theRequestWithKeyWord:mykeyword];
    });
}
- (void)footerRereshing{
    // 2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KRefreshTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //getMarriageSeeking(网络请求)
        //        [self loadMoreDataRequestWithKeyWord:mykeyword];
        
    });
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 2) {
        return 10;
    }else{
        return 1;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *cellid = [NSString stringWithFormat:@"textfield%ld",(long)indexPath.row];
    NewFuLiTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
    if (cell == nil) {
        cell = [[NewFuLiTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid cellType:(indexPath.section == 2?ThreeType:(indexPath.section == 1?TwoType:OneType))];
    }
    [cell setValueWithModel:indexPath];
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 2) {
         return [NewFuLiTableViewCell TypeCellgetcellHeight];
    }else{
         return [NewFuLiTableViewCell DefualtgetcellHeight];
    }
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 40;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    switch (section) {
        case 0:
            return [self layoutHeaderViewWithTitle:@"日常福利" HeaderimageName:@"日常.png" footerIamgeName:@"日常福利点缀.png"];
            break;
        case 1:
            return [self layoutHeaderViewWithTitle:@"限时福利" HeaderimageName:@"限时.png" footerIamgeName:@"限时福利点缀.png"];
            break;
        case 2:
            return [self layoutHeaderViewWithTitle:@"往期福利" HeaderimageName:@"往期icon.png" footerIamgeName:@"往期福利点缀.png"];
            break;
        default:
            
            break;
    }
    return nil;
}
- (UIView *)layoutHeaderViewWithTitle:(NSString *)title HeaderimageName:(NSString *)headerImageName footerIamgeName:(NSString *)footerIamgename{
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, 40)];
    view.backgroundColor = [UIColor whiteColor];
    UIImageView *headerImageV = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 20, 20)];
    headerImageV.image = [UIImage imageNamed:headerImageName];
    [view addSubview:headerImageV];
    
    UILabel *titleLabel = [UILabel initWithFrame:CGRectMake(KVIEW_X(headerImageV)+10, 20, KCONTROLLERWith, 20) text:title font:13 textAlignment:NSTextAlignmentLeft texcolor:[df colorWithHexString:@"333333" alpha:1] backgroundColor:nil];
    [view addSubview:titleLabel];
    CGFloat footerImageVWidth = 20*88/37;
    UIImageView *footerImageV = [[UIImageView alloc]initWithFrame:CGRectMake(KCONTROLLERWith-20-footerImageVWidth, 20, footerImageVWidth, 20)];
    footerImageV.image = [UIImage imageNamed:footerIamgename];
    [view addSubview:footerImageV];
    
    
    
    return view;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
